import type { VxeTableGridOptions } from '@vben/plugins/vxe-table';

import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn } from '#/adapter/vxe-table';
import type { WareHouse } from '#/api';

/**
 * 获取人员编辑表单的字段配置
 */
export function useSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'deptId',
      dependencies: {
        triggerFields: ['deptId'],
        show: false,
      },
    },
    {
      component: 'Input',
      componentProps: {
        placeholder: '请输入用户名称',
        allowClear: true,
        class: 'mr-5',
      },
      fieldName: 'userName',
      label: '用户名称',
      labelClass: 'w-auto text-[#606266] font-bold',
    },
    {
      component: 'Input',
      componentProps: {
        placeholder: '请输入手机号码',
        allowClear: true,
      },
      fieldName: 'phonenumber',
      label: '手机号码',
      labelClass: 'w-auto text-[#606266] font-bold',
    },
  ];
}

/**
 * 获取表格列配置
 * @param _onActionClick 表格操作按钮点击事件
 */
export function useColumns(
  _onActionClick?: OnActionClickFn<WareHouse.Row>,
): VxeTableGridOptions<WareHouse.Row>['columns'] {
  return [
    {
      field: 'id',
      fixed: 'left',
      type: 'radio',
      width: 50,
    },
    {
      field: 'userName',
      title: '用户名称',
    },
    {
      field: 'nickName',

      title: '用户昵称',
    },
    {
      field: 'dept',
      title: '部门',
      formatter: ({ cellValue }) => {
        return cellValue?.deptName;
      },
    },
    {
      field: 'phonenumber',
      title: '手机号码',
    },
    {
      field: 'createTime',
      title: '创建时间',
    },
  ];
}
